/*!
 *  Application Entry
 */

module com.yakool {

    class Page {
        root: any;

        init(): void { }
        show(): void { this.root.show(); }
        hide(): void { this.root.hide(); }
    }
    class LoginPage extends Page {
        init(): void {
            this.root = $("#page-login");
            //this.bind();
        }
    }
    class DashboardPage extends Page {
    }
    class LoadingPage extends Page {
    }
    class OrderPage extends Page {
    }

    class App {
        static _instance: App;
        pages: Array<Page>;

        constructor() {
            this.pages = [new LoadingPage(), new LoginPage(), new DashboardPage(), new OrderPage()];
            this.init();
        }

        static instance(): App {
            if (!this._instance) {
                this._instance = new App();
            }
            return this._instance;
        }

        init(): void {
            this.pages.forEach(p=> p.init());
            // goto login page
            this.to(this.pages[1]);
        }

        to(page: Page): void {
            this.pages.forEach(p=> {
                if (p === page) {
                    p.show();
                } else {
                    p.hide();
                }
            });
        }
        setup(): void {
        }
    }

    $(function () {
        App.instance().setup();
    });
}